<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String mark = request.getParameter("mark") == null ? "" : request.getParameter("mark").toString().trim();
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0" />
	<title>微信资源管理</title>
	<link rel="stylesheet" href="<%=path %>/skin/default/css/button.css" type="text/css" />
	<link rel="stylesheet" href="<%=path %>/scripts/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css" />
	
	<script type="text/javascript" src="<%=path %>/scripts/jquery/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="<%=path %>/scripts/zTree/jquery.ztree.core-3.0.min.js"></script>
	<script type="text/javascript" src="<%=path %>/scripts/zTree/jquery.ztree.excheck-3.0.js"></script>
	<script type="text/javascript" src="<%=path %>/scripts/zTree/jquery.ztree.buttons.js"></script>
	<script type="text/javascript">
		$(function(){
			$.ajaxSetup({cache:false,async:false});
			var setting = {
				check : {
					enable : true,
					chkStyle : "radio",
					radioType : "all"
				},
				view : {
					dblClickExpand : false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onClick: zTreeOnClick,
					onCheck: zTreeonCheck
				}
			};
			var dataMaker = function(){
				var nodes = [];
				var p = {id:"0",pId:"-1",name:"资源管理",code:"0",open:true,nocheck:true,icon:"<%=path %>/scripts/zTree/css/zTreeStyle/img/diy/1_close.png"};
				nodes.push(p);
				$.getJSON("<%=path %>/resource/List",function(result){
					if(result != null){
						$.each(result,function(i,item){
							var h = {id:item.appId,pId:"0",name:item.appName,code:item.id,open:true};
							nodes.push(h);
						});
					}
				});
				return nodes;
			};
			var zNodes = dataMaker();
			function zTreeOnClick(event, treeId, treeNode) {
				if(!treeNode.isParent){
					var zTree = $.fn.zTree.getZTreeObj(treeId);
					zTree.checkNode(treeNode, !treeNode.checked, null, true);
					return false;
				}
			}
			function zTreeonCheck(event, treeId, treeNode){
				var zTree = $.fn.zTree.getZTreeObj(treeId);
				var nodes = zTree.getCheckedNodes(true);
				$.each(nodes,function(key,item){
					$("#node").val(item.id);
				});
			}
			$(document).ready(function(){ 
				$.fn.zTree.init($("#resourceTree"), setting, zNodes);
				var mark = '<%=mark %>';
				var opts = {
					submitUrl:"<%=path %>/wechat/menu/Create?mark="+mark,
					submitBtn:"btnSubmit",
					closeBtn:"btnClose",
					node:"node"
				};
				closeClick(opts);
				syncClick(opts);
			});
		});
	</script>
</head>
<body>
	<div class="content_wrap" >
		<ul id="resourceTree" class="ztree"></ul>
	</div>
	<div class="bottomBar">
		<div class="fr" style="margin-right: 10px;">
			<input type="hidden" id="node" name="node" value=""/>
			<input type="button" id="btnSubmit" name="btnSubmit" class="btn btn82 btn_save_bottom" value="确 定" />
			<input type="button" id="btnClose" name="btnClose" class="btn btn82 btn_close" value="关 闭" />
		</div>
	</div>
</body>
</html>